package py.edu.ucom.cadira.testWar;

import py.edu.ucom.cadira.game.event.GameEvent;
import py.edu.ucom.cadira.game.war.Board;
import py.edu.ucom.cadira.game.war.GameListener;
import py.edu.ucom.cadira.game.war.Movement;
import py.edu.ucom.cadira.game.war.Square;
import py.edu.ucom.cadira.game.war.Tab;
import py.edu.ucom.cadira.game.war.WarGame;
import py.edu.ucom.cadira.game.war.WarUser;

/**
 *
 * @author SYSTEM02
 */
public class WarTest implements GameListener {

    boolean status = false;

    public static void main(String args[]) {
        WarUser user1 = new WarUser("Largo", "largonet");
        WarUser user2 = new WarUser("Hernan", "chucky");
        WarTest t = new WarTest();
        //WarGame war = new WarGame();
        Board tablero1 = new Board();
        Board tablero2 = new Board();
        Tab tab1[] = new Tab[40];
        Tab tab2[] = new Tab[40];
        Tool tool = new Tool();
        
        tablero1.initializeSquareInBoard();
        tablero2.initializeSquareInBoard();
        tool.addListener(t);
        tool.registrar(user1,0);
        tool.registrar(user2,0);
        tool.startGame();
        tab1 = tool.crearFichaParaAgente(tab1,user1.getColor());
        tab2 = tool.crearFichaParaAgente(tab2,user2.getColor());
        
        tool.setearFicha(tab1);
        tool.setearFicha(tab2);
        tablero1 = tool.armarBoardInicial(tablero1,tab1,2);
        tablero2 = tool.armarBoardInicial(tablero2,tab2,2);
        tool.setBoard(user1,tablero1);
        System.out.println("**********TABLERO1**********");
        tool.imprimirTablero(tablero1);
        System.out.println("*************************");
        tool.setBoard(user2,tablero2);
        System.out.println("**********TABLERO2**********");
        tool.imprimirTablero(tablero2);
        System.out.println("*************************");
        System.out.println("*************************");
        tool.imprimirTablero();
        System.out.println("*************************");
        if (user1.getColor() == WarGame.COLOR_RED){
            // Player 1
            Movement m = new Movement();
            Square casilla = new Square(4,0);
            m.setOrigen(tablero1.getSquareFromBoard(3,0));
            m.setDestino(casilla);
            tool.moveTab(m, user1);
            tablero1 = tool.getBoard(user1);
            tool.imprimirTablero();
            
            // Player 2
            m.setOrigen(tablero2.getSquareFromBoard(6,0));
            Square casilla1 = new Square(5,0);
            m.setDestino(casilla1);
            tool.moveTab(m, user2);
            tablero2 = tool.getBoard(user2);
            tool.imprimirTablero();
            
            // Player 1
            m = new Movement();
            casilla = tablero1.getSquareFromBoard(5,0);
            m.setOrigen(tablero1.getSquareFromBoard(4,0));
            m.setDestino(casilla);
            tool.moveTab(m, user1);
            tablero1 = tool.getBoard(user1);
            tool.imprimirTablero();

        }else{
            Movement m = new Movement();
            Square casilla1 = new Square(5,0);
            m.setOrigen(tablero2.getSquareFromBoard(6,0));
            m.setDestino(casilla1);
            tool.moveTab(m, user2);
            tool.imprimirTablero();
        }
    }

    public void eventHappened(GameEvent event) {
//        if (event instanceof SetTabUserEvent) {
//            SetTabUserEvent tab = (SetTabUserEvent) event;
//            System.out.print("Event.SetTabUserEvent: Tablero y Fichas enviados por el server\n");
//            //System.out.print("SetTabUserEvent");
//        }else{
//            if (event instanceof PlayUserEvent) {
//                //System.out.print(event);
//             System.out.println("PlayUserEvent");
//            }
//        }
        System.out.print(event);
    }
}
